package com.abbas.smartCity.ui;

import android.annotation.SuppressLint;
import android.webkit.WebView;
import android.widget.TextView;

import com.abbas.smartCity.R;
import com.abbas.smartCity.base.BaseActivity;
import com.abbas.smartCity.bean.HomeNewsDetailBean;
import com.abbas.smartCity.retroft.ICallback;

import retrofit2.Call;

/**
 * 新闻详情页面
 */
public class DetailActivity extends BaseActivity {

    private TextView title;
    private TextView sub;
    private WebView web;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_detail;
    }

    @Override
    protected String setCustomTitle() {
        return "新闻详情";
    }

    @Override
    protected void initView() {
        title = (TextView) findViewById(R.id.title);
        sub = (TextView) findViewById(R.id.sub);
        web = (WebView) findViewById(R.id.web);
    }

    @Override
    protected void initData() {
        final int id = getIntent().getIntExtra("id", -1);

        api.getHomeNewsDetail(id).enqueue(new ICallback<HomeNewsDetailBean>() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onSuccess(Call<HomeNewsDetailBean> call, HomeNewsDetailBean data) {
                final HomeNewsDetailBean.DataBean data1 = data.getData();

                title.setText(data1.getTitle());
                sub.setText("发布时间："+data1.getPublishDate());
                web.loadDataWithBaseURL(null,data1.getContent(),null,null,null);
            }
        });
    }

    @Override
    protected void initEvent() {

    }
}